package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

/**
 * 系统指标分类的alias枚举
 * 目前该枚举不全，未罗列全部alias，只有首页分类alias
 *
 * @author 徐俊杰
 * @version v1.0
 * @date 2019/1/31 9:51
 * @since v1.0
 */
@Getter
public enum ChartCategoryAliasEnum {
    /**
     * 首页图表分类alias
     */
    // https://xbb.yuque.com/xbb/vsf9sv/eb8vkc 消息卡片（砍掉）
    // NEW_MESSAGE("newMessage", "新消息", ChartTypeEnum.VALUE.getCode(), XbbRefTypeEnum.UNKNOWN.getAlias()),
    SALES_REPORT("salesReport", "enum.chartCategoryAlias.name.sales_report", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    ANNOUNCEMENT("announcement", "enum.chartCategoryAlias.name.announcement", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    RAIDERS("raiders", "enum.chartCategoryAlias.name.raiders", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    APPROVAL("approval", "enum.chartCategoryAlias.name.approval", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.PROCESS.getAlias(), XbbRefTypeEnum.APPROVAL.getCode()),
    APPROVAL_PROGRESS("approvalProgress", "enum.chartCategoryAlias.name.approval_progress", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.PROCESS.getAlias(), XbbRefTypeEnum.APPROVAL.getCode()),
    COMMUNICATE_PLAN("communicatePlan", "enum.chartCategoryAlias.name.communicate_plan", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.COMMUNICATE_PLAN.getAlias(), XbbRefTypeEnum.COMMUNICATE_PLAN.getCode()),
    // 跟进提醒由：客户跟进记录、供应商跟进记录组成
    REMIND("remind", "enum.chartCategoryAlias.name.remind", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    // TODO 当前为遗忘客户，扩展到机会时再修改
    FORGET_REMIND("forgetRemind", "enum.chartCategoryAlias.name.forget_remind", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.CUSTOMER_MANAGEMENT.getAlias(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    STOCK_WARNING("stockWarning", "enum.chartCategoryAlias.name.stock_warning", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.STOCK_SEARCH.getAlias(), XbbRefTypeEnum.STOCK_SEARCH.getCode()),
    CUSTOMER_CARE("customerCare", "enum.chartCategoryAlias.name.customer_care", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.CUSTOMER_MANAGEMENT.getAlias(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    KE_FU("kefu", "enum.chartCategoryAlias.name.ke_fu", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    REPORT_BOARD("reportBoard", "enum.chartCategoryAlias.name.report_board", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    PK("pk", "enum.chartCategoryAlias.name.pk", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.UNKNOWN.getAlias(), XbbRefTypeEnum.UNKNOWN.getCode()),
    PERFORMANCE("performance", "enum.chartCategoryAlias.name.performance", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.PERFORMANCE_OBJECT_SET.getAlias(), XbbRefTypeEnum.PERFORMANCE.getCode()),
    CUSTOMER("customer", "enum.chartCategoryAlias.name.customer", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.CUSTOMER_MANAGEMENT.getAlias(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()),
    OPPORTUNITY("opportunity", "enum.chartCategoryAlias.name.opportunity", ChartTypeEnum.FUNNEL_COMMON.getCode(), ProPermissionAliasEnum.SALES_OPPORTUNITY.getAlias(), XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()),
    CONTRACT("contract", "enum.chartCategoryAlias.name.contract", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.CONTRACT.getAlias(), XbbRefTypeEnum.CONTRACT.getCode()),
    PAYMENT("payment", "enum.chartCategoryAlias.name.payment", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.PAYMENT.getAlias(), XbbRefTypeEnum.PAYMENT.getCode()),
    PAY("pay", "enum.chartCategoryAlias.name.pay", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.PAY_PLAN.getAlias(), XbbRefTypeEnum.PAY_PLAN.getCode()),
    PURCHASE("purchase", "enum.chartCategoryAlias.name.purchase", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.PURCHASE.getAlias(), XbbRefTypeEnum.PURCHASE.getCode()),
    WORK_ORDER("workOrder", "enum.chartCategoryAlias.name.work_order", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.WORK_ORDER.getAlias(), XbbRefTypeEnum.WORK_ORDER.getCode()),
    QUOTATION("quotation", "enum.chartCategoryAlias.name.quotation", ChartTypeEnum.LINE_CHART.getCode(), ProPermissionAliasEnum.QUOTATION.getAlias(), XbbRefTypeEnum.QUOTATION.getCode()),
    FUND_MANAGEMENT("fundManagement", "enum.chartCategoryAlias.name.fund_management", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.FUND_MANAGEMENT.getAlias(), XbbRefTypeEnum.FUND_MANAGEMENT.getCode()),
    PENDING_WORK_ORDER("pendingWorkOrder", "enum.chartCategoryAlias.name.pending_work_order", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.WORK_ORDER.getAlias(), XbbRefTypeEnum.WORK_ORDER.getCode()),
    SALE_CLUE_CHART("saleClue", "enum.chartCategoryAlias.name.sale_clue_chart", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.CLUE.getAlias(), XbbRefTypeEnum.CLUE.getCode()),
    DATA_WARNING("dataWarning", "enum.chartCategoryAlias.name.data_warning", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.DATA_CENTER.getAlias(), XbbRefTypeEnum.STATISTICS.getCode()),
    WORK_ORDER_V2("workOrderV2", "enum.chartCategoryAlias.name.work_order_v2", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.WORK_ORDER_V2.getAlias(), XbbRefTypeEnum.WORK_ORDER_V2.getCode()),
    RECEIPT_ORDER("receiptOrder", "enum.chartCategoryAlias.name.receipt_order", ChartTypeEnum.VALUE.getCode(),  ProPermissionAliasEnum.RECEIPT_ORDER.getAlias(), XbbRefTypeEnum.RECEIPT_ORDER.getCode()),

    PENDING_WORK_ORDER_V2("pendingWorkOrderV2", "enum.chartCategoryAlias.name.pending_work_order_v2", ChartTypeEnum.VALUE.getCode(), ProPermissionAliasEnum.WORK_ORDER_V2.getAlias(), XbbRefTypeEnum.WORK_ORDER_V2.getCode()),
    ;
    /**
     * 英文名
     */
    private String alias;
    /**
     * 中文名
     */
    private String name;
    /**
     * 默认展示方式
     */
    private Integer showType;
    /**
     * 业务类型
     */
    private String proPermissionAlias;
    /**
     * 业务类型
     */
    private Integer businessType;

    ChartCategoryAliasEnum(String alias, String name, Integer showType, String proPermissionAlias, Integer businessType) {
        this.alias = alias;
        this.name = name;
        this.showType = showType;
        this.proPermissionAlias = proPermissionAlias;
        this.businessType = businessType;
    }

    /**
     * 通过别名获取ChartCategoryAliasEnum
     * @param alias 别名
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-03-11 20:37
     * @since v1.0
     * @version v1.0
     */
    public static ChartCategoryAliasEnum getByAlias(String alias) {
        for (ChartCategoryAliasEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getAlias(), alias)) {
                return cacheCode;
            }
        }
        return null;
    }

    /**
     * 可跟进到列表：访客计划列表、仓库预警列表、待处理工单列表
     * @param
     * @return
     * @throws
     * @author hongxiao
     * @date 2019-06-26 10:57
     * @since
     * @version
     */
    public static ChartCategoryAliasEnum jump2BusinessByAlias(String alias) {
        List<ChartCategoryAliasEnum> list = Arrays.asList(COMMUNICATE_PLAN, STOCK_WARNING, PENDING_WORK_ORDER,PENDING_WORK_ORDER_V2);
        for (ChartCategoryAliasEnum aliasEnum : list) {
            if(Objects.equals(aliasEnum.getAlias(), alias)) {
                return aliasEnum;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getNameEn() {
        return I18nMessageUtil.getMessage(name,Locale.US);
    }
}
